App({
  onLaunch(options) {
    // 第一次打开
    // options.query == {number:1}
    this.globalData.corpId = options.query.corpId;
    if (this.globalData.userInfo == null) {
      dd.getAuthCode({
        success: (res) => {
          dd.httpRequest({
            url: this.globalData.url + '/login',
            method: 'POST',
            data: {
              authCode: res.authCode
            },
            dataType: 'json',
            success: (res) => {
              // dd.alert({content: "step2"});
              console.log('success----', res)
              this.globalData.userInfo = res.data.data;
              console.log(this.globalData.userInfo)
              dd.setStorage({
                key: 'userInfo',
                data: res.data.data,
                success: function() {
                  // dd.alert({content: '写入成功'});
                }
              });
            },
            fail: (res) => {
              console.log("httpRequestFail---", res)
              dd.alert({ content: JSON.stringify(res) });
            },
            complete: (res) => {
              dd.hideLoading();
            }
          });
        },
        fail: (err) => {
          dd.alert({ content: "step3" });
          dd.alert({
            content: JSON.stringify(err)
          })
        }
      })
    }
  },
  onShow(options) {
    // 从后台被 scheme 重新打开
    // options.query == {number:1}
  },
  globalData: {
    userInfo: null,
    url: 'http://localhost:8080',
    corpId: null
  }
});
